package com.tjsoft.demo.student.action;

import java.util.HashMap;

import org.hibernate.mapping.Map;

import com.tjsoft.demo.student.service.FreshCutService;

public class FreshCutAction extends BaseAction{
	private FreshCutService  productService;
	public FreshCutService getProductService() {
		return productService;
	}
	public void setProductService(FreshCutService productService) {
		this.productService = productService;
	}
	
	public String studentList() throws Exception{
		 int  sort=Integer.valueOf(request.getParameter("num"));//srot分类
		 System.out.println(sort+"--------商品列表-----------");
		// out.print();
		 String product=productService.findListFreshCut(sort);
		 response.setContentType("text/html; charset=UTF-8");
		 response.getWriter().println(product);
		 // request.setAttribute("productList", product);
		 return null;
	}
	
	public String  showProductDetail(){
		try{
	     String temp=request.getParameter("productId");
		  if(temp!=null||!temp.isEmpty()){
	     int productId=Integer.valueOf(temp);
	    	String productDetail=productService.showProductDetail(productId);
	    	response.setContentType("text/html; charset=UTF-8");
		 	response.getWriter().println(productDetail);
		    System.out.println("商品详情"+productDetail);
		}}catch(Exception e){
			//id为空
			System.out.println(e);
		}
		return null;
	}
	//查看购物车,并查看
   public String addToCartOrBrowse(){
	    try{
	    	  String[] purchers=request.getParameterValues("fruits[]");//request.getParameter("tuan_ids[]");
	    	  String[] counts=request.getParameterValues("counts[]");
	    	  String  userId=request.getParameter("userId");
	    	  String  cartId=request.getParameter("cartId");
	    	  //将商品添加到购物车，然后返回购买的商品
	          String  cartdetail=productService.addToCart(userId,cartId,purchers,counts);
	          response.setContentType("text/html; charset=UTF-8");
	          response.getWriter().println(cartdetail);
	      //   users = java.net.URLDecoder.decode(users, "utf-8");
	      //map=request.getParameter("tuan_ids[]")
	      //  System.out.println("ur request.getRealPath"+users);
	       
	    }catch(Exception e){
	    	e.printStackTrace();
	    }
	   
	   return null;
   }
   //提交订单，并生成订单列表
   public String submitOrders(){
	   try{
		   String userId=request.getParameter("userId");
		   String cartId=request.getParameter("cartId");
		   String[] purchers=request.getParameterValues("fruits[]");//request.getParameter("tuan_ids[]");
	       String[] counts=request.getParameterValues("counts[]");
	       String  orderList=productService.submitOrder(userId, cartId, purchers, counts); 
	       response.setContentType("text/html; charset=UTF-8");
	       response.getWriter().println(orderList);
	   }catch(Exception e){}
	   
	   return null;
   }
}
